package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.CoreWorkOrderDto;
import com.corechina.apex_osswords.domain.dto.CoreWorkOrderListDto;
import com.corechina.apex_osswords.domain.entity.CoreWorkOrder;
import com.corechina.apex_osswords.service.ICoreProjectUserService;
import com.corechina.apex_osswords.service.ICoreWorkOrderService;
import com.sun.istack.internal.NotNull;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 * 工单表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-03-11
 */
@Api(tags = "工单相关")
@RestController
@RequestMapping("/core/workOrder")
public class CoreWorkOrderController {

    @Autowired
    private ICoreWorkOrderService iCoreWorkOrderService;

    @Autowired
    private ICoreProjectUserService iCoreProjectUserService;

    @ApiOperation("新增")
    @SysLog("新增工单")
    @PostMapping("/add")
    public Response add(@RequestBody CoreWorkOrderDto coreWorkOrderDto) {
        return iCoreWorkOrderService.add(coreWorkOrderDto);
    }

    @ApiOperation("新增定期工单")
    @SysLog("新增定期工单")
    @PostMapping("/addForList")
    public Response addForList(@RequestBody CoreWorkOrderListDto coreWorkOrderListDto) {
        return iCoreWorkOrderService.addForList(coreWorkOrderListDto);
    }


    @ApiOperation("编辑工单")
    @SysLog("编辑工单")
    @PutMapping("/update")
    public Response update(@RequestBody CoreWorkOrderDto coreWorkOrderDto) {
        return iCoreWorkOrderService.update(coreWorkOrderDto);
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(Integer equipmentId, Integer sortType, String beginDate, String endDate, Integer warningDay, String projectName, String state, Integer disposeResult, Integer createUserType, String recipientName, Integer pageIndex, Integer pageSize) {
        return iCoreWorkOrderService.getList(equipmentId, sortType, beginDate, endDate, warningDay, projectName, state, disposeResult, createUserType, recipientName, pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iCoreWorkOrderService.getOne(id);
    }

    @ApiOperation("删除")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        iCoreWorkOrderService.removeById(id);
        return Response.ok();
    }

    @ApiOperation("获取循环工单日期")
    @GetMapping("/getRemindList")
    public Response getRemindList(@RequestParam @NotNull @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate beginDate, @RequestParam @NotNull @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, Integer type, Integer frequency) {
        return iCoreWorkOrderService.getRemindList(beginDate, endDate, type, frequency);
    }

    @ApiOperation("增加指定处理人")
    @PostMapping("/updateRecipient")
    public Response updateRecipient(@RequestBody CoreWorkOrder coreWorkOrder) {
        return iCoreWorkOrderService.updateRecipient(coreWorkOrder);
    }

    @ApiOperation("修改工单状态")
    @GetMapping("/updateState")
    public Response updateOrderState(Integer state, Integer id) {
        return iCoreWorkOrderService.updateOrderState(state, id);
    }


    @ApiOperation("获取项目相关运维人员列表")
    @GetMapping("/getProjectEngineerList")
    public Response getProjectEngineerList(Integer projectId, String name, String company, Integer engineerType, Integer pageIndex, Integer pageSize) {
        return iCoreProjectUserService.getProjectPersonnelList(1, projectId, name, company, engineerType, pageIndex, pageSize);
    }

}

